package main

import (
	"3rd/utils"
	"bytes"
	"code.google.com/p/mahonia"
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"github.com/gorilla/http"
	"github.com/ylywyn/jpush-api-go-client"
	"net/url"
)

const (
	appKey = "b8a86fc270ad92e417145a22"
	secret = "d47ff90663c95614e1197962"
)

func main() {
	fmt.Println(utils.BitArray(1))
	h := md5.New()
	h.Write([]byte("yanzmfx"))                         // 需要加密的字符串为 sharejs.com
	fmt.Printf("%s\n", hex.EncodeToString(h.Sum(nil))) //

	enc := mahonia.NewEncoder("gbk")
	if ret, ok := enc.ConvertStringOK(url.QueryEscape("你好啊")); ok {
		fmt.Println("UTF-8 to GBK: ", ret, " bytes: ", []byte(ret))
	}

	//fmt.Println(url.QueryEscape("你好啊"))

	return
	v := url.Values{}
	v.Add("user", "sk")
	v.Add("password", "pwd")
	v.Add("tele", "123")
	v.Add("msg", "hh")
	param := v.Encode()
	fmt.Println(param)
	return
	var b bytes.Buffer
	http.Get(&b, "http://183.57.76.50:8080/sms/sendsms?user=yanzmfx&password=3f4d984a943d4ebcfe9d9c6112da9c7d&tele=18530950471&msg=%c4%e3%ba%c3%a3%ac%c4%e3%b5%c4%d1%e9%d6%a4%c2%eb%ca%c75547")
	fmt.Println(b.String())
	return
	//Platform
	var pf jpushclient.Platform
	pf.Add(jpushclient.ANDROID)
	pf.Add(jpushclient.IOS)
	pf.Add(jpushclient.WINPHONE)
	//pf.All()

	//Audience
	var ad jpushclient.Audience
	//s :=
	//ad.SetTag([]string{"tai"})
	ad.SetAlias([]string{"sk"})
	//ad.SetID([]string{"080b581e9ac"})
	//ad.All()

	//Notice
	var notice jpushclient.Notice
	notice.SetAlert("alert")
	//notice.SetAndroidNotice(&jpushclient.AndroidNotice{Alert: "hello,sk"})
	notice.SetIOSNotice(&jpushclient.IOSNotice{Alert: "IOSNotice"})
	notice.SetWinPhoneNotice(&jpushclient.WinPhoneNotice{Alert: "WinPhoneNotice"})

	var msg jpushclient.Message
	//msg.Title = "title"
	msg.Content = "msg"
	msg.Extras = map[string]interface{}{
		"_id": "123",
	}

	payload := jpushclient.NewPushPayLoad()
	payload.SetPlatform(&pf)
	payload.SetAudience(&ad)
	payload.SetMessage(&msg)
	payload.SetNotice(&notice)

	bytes, _ := payload.ToBytes()
	fmt.Printf("%s\r\n", string(bytes))

	//push
	c := jpushclient.NewPushClient(secret, appKey)
	str, err := c.Send(bytes)
	if err != nil {
		fmt.Printf("err:%s", err.Error())
	} else {
		fmt.Printf("ok:%s", str)
	}
}
